using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;

using PickGold.Charting.ChartTypes;
using PickGold.Charting.Data;
using PickGold.Charting.Design;
using PickGold.Charting.Utilities;

namespace PickGold.Charting
{
	[DefaultProperty("Points")]
	[SRDescription("DescriptionAttributeSeries_Series")]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class Series : DataPointCustomProperties
	{
		private string _chartArea;
		private string _chartType;
		private bool _checkPointsNumber;
		private ChartColorPalette _colorPalette;
		private string _dataSourceXMember;
		private string _dataSourceYMembers;
		private double[] _dummyDoubleValues;
		private DataPointCustomProperties _emptyPointCustomProperties;
		private bool _enabled;
		private FontCache _fontCache;
		private bool _isXValueIndexed;
		private string _legend;
		private int _markersStep;
		private DataPointCollection _points;
		private Color _shadowColor;
		private int _shadowOffset;
		private SmartLabelStyle _smartLabelStyle;
		private double _totalYvalue;
		private AxisType _xAxisType;
		private ChartValueType _xValueType;
		private AxisType _yAxisType;
		private int _yValuesPerPoint;
		private ChartValueType _yValueType;
		internal bool autoXValueType;
		internal bool autoYValueType;
		internal string axisLabel;
		internal GradientStyle backGradientStyle;
		internal ChartHatchStyle backHatchStyle;
		internal string backImage;
		internal ChartImageAlignmentStyle backImageAlignment;
		internal Color backImageTransparentColor;
		internal ChartImageWrapMode backImageWrapMode;
		internal Color backSecondaryColor;
		internal Color borderColor;
		internal ChartDashStyle borderDashStyle;
		internal int borderWidth;
		internal Color color;
		internal static DataPointCustomProperties defaultCustomProperties = InitializeDefaultCustomProperties();
		internal DataPointCollection fakeDataPoints;
		internal Font font;
		internal int fontAngle;
		internal Color fontColor;
		internal ChartValueType indexedXValueType;
		internal string label;
		internal Color labelBackColor;
		internal Color labelBorderColor;
		internal ChartDashStyle labelBorderDashStyle;
		internal int labelBorderWidth;
		internal string labelFormat;
		internal string labelMapAreaAttributes;
		internal string labelPostbackValue;
		internal string labelToolTip;
		internal string labelUrl;
		internal string legendMapAreaAttributes;
		internal string legendPostbackValue;
		internal string legendText;
		internal string legendToolTip;
		internal string legendUrl;
		internal string mapAreaAttributes;
		internal Color markerBorderColor;
		internal int markerBorderWidth;
		internal Color markerColor;
		internal string markerImage;
		internal Color markerImageTransparentColor;
		internal int markerSize;
		internal MarkerStyle markerStyle;
		internal bool noLabelsInPoints;
		internal string postbackValue;
		internal bool showInLegend;
		internal bool showLabelAsValue;
		internal bool tempMarkerStyleIsSet;
		internal string toolTip;
		internal string url;
		internal bool xValuesZeros;
		internal bool xValuesZerosChecked;

		public Series()
			: base(null, false)
		{
			this._yValuesPerPoint = 1;
			this._markersStep = 1;
			this._shadowColor = Color.FromArgb(0x80, 0, 0, 0);
			this._chartType = "Column";
			this._chartArea = string.Empty;
			this._enabled = true;
			this._legend = string.Empty;
			this._dataSourceXMember = string.Empty;
			this._dataSourceYMembers = string.Empty;
			this._totalYvalue = double.NaN;
			this._checkPointsNumber = true;
			this.noLabelsInPoints = true;
			this.label = "";
			this.axisLabel = "";
			this.labelFormat = "";
			this.color = Color.Empty;
			this.borderColor = Color.Empty;
			this.borderDashStyle = ChartDashStyle.Solid;
			this.borderWidth = 1;
			this.markerBorderWidth = 1;
			this.backImage = "";
			this.backImageTransparentColor = Color.Empty;
			this.backSecondaryColor = Color.Empty;
			this._fontCache = new FontCache();
			this.fontColor = Color.Black;
			this.markerSize = 5;
			this.markerImage = "";
			this.markerImageTransparentColor = Color.Empty;
			this.markerColor = Color.Empty;
			this.markerBorderColor = Color.Empty;
			this.toolTip = "";
			this.url = "";
			this.mapAreaAttributes = "";
			this.postbackValue = "";
			this.showInLegend = true;
			this.legendText = "";
			this.legendToolTip = "";
			this.labelBackColor = Color.Empty;
			this.labelBorderColor = Color.Empty;
			this.labelBorderDashStyle = ChartDashStyle.Solid;
			this.labelBorderWidth = 1;
			this.labelToolTip = "";
			this.labelUrl = "";
			this.labelMapAreaAttributes = "";
			this.labelPostbackValue = "";
			this.legendUrl = "";
			this.legendMapAreaAttributes = "";
			this.legendPostbackValue = "";
			this.InitProperties(null, 0);
		}

		public Series(string name)
			: base(null, false)
		{
			this._yValuesPerPoint = 1;
			this._markersStep = 1;
			this._shadowColor = Color.FromArgb(0x80, 0, 0, 0);
			this._chartType = "Column";
			this._chartArea = string.Empty;
			this._enabled = true;
			this._legend = string.Empty;
			this._dataSourceXMember = string.Empty;
			this._dataSourceYMembers = string.Empty;
			this._totalYvalue = double.NaN;
			this._checkPointsNumber = true;
			this.noLabelsInPoints = true;
			this.label = "";
			this.axisLabel = "";
			this.labelFormat = "";
			this.color = Color.Empty;
			this.borderColor = Color.Empty;
			this.borderDashStyle = ChartDashStyle.Solid;
			this.borderWidth = 1;
			this.markerBorderWidth = 1;
			this.backImage = "";
			this.backImageTransparentColor = Color.Empty;
			this.backSecondaryColor = Color.Empty;
			this._fontCache = new FontCache();
			this.fontColor = Color.Black;
			this.markerSize = 5;
			this.markerImage = "";
			this.markerImageTransparentColor = Color.Empty;
			this.markerColor = Color.Empty;
			this.markerBorderColor = Color.Empty;
			this.toolTip = "";
			this.url = "";
			this.mapAreaAttributes = "";
			this.postbackValue = "";
			this.showInLegend = true;
			this.legendText = "";
			this.legendToolTip = "";
			this.labelBackColor = Color.Empty;
			this.labelBorderColor = Color.Empty;
			this.labelBorderDashStyle = ChartDashStyle.Solid;
			this.labelBorderWidth = 1;
			this.labelToolTip = "";
			this.labelUrl = "";
			this.labelMapAreaAttributes = "";
			this.labelPostbackValue = "";
			this.legendUrl = "";
			this.legendMapAreaAttributes = "";
			this.legendPostbackValue = "";
			if (name == null)
			{
				throw new ArgumentNullException(SR.ExceptionDataSeriesNameIsEmpty);
			}
			this.InitProperties(name, 0);
		}

		public Series(string name, int yValues)
			: base(null, false)
		{
			this._yValuesPerPoint = 1;
			this._markersStep = 1;
			this._shadowColor = Color.FromArgb(0x80, 0, 0, 0);
			this._chartType = "Column";
			this._chartArea = string.Empty;
			this._enabled = true;
			this._legend = string.Empty;
			this._dataSourceXMember = string.Empty;
			this._dataSourceYMembers = string.Empty;
			this._totalYvalue = double.NaN;
			this._checkPointsNumber = true;
			this.noLabelsInPoints = true;
			this.label = "";
			this.axisLabel = "";
			this.labelFormat = "";
			this.color = Color.Empty;
			this.borderColor = Color.Empty;
			this.borderDashStyle = ChartDashStyle.Solid;
			this.borderWidth = 1;
			this.markerBorderWidth = 1;
			this.backImage = "";
			this.backImageTransparentColor = Color.Empty;
			this.backSecondaryColor = Color.Empty;
			this._fontCache = new FontCache();
			this.fontColor = Color.Black;
			this.markerSize = 5;
			this.markerImage = "";
			this.markerImageTransparentColor = Color.Empty;
			this.markerColor = Color.Empty;
			this.markerBorderColor = Color.Empty;
			this.toolTip = "";
			this.url = "";
			this.mapAreaAttributes = "";
			this.postbackValue = "";
			this.showInLegend = true;
			this.legendText = "";
			this.legendToolTip = "";
			this.labelBackColor = Color.Empty;
			this.labelBorderColor = Color.Empty;
			this.labelBorderDashStyle = ChartDashStyle.Solid;
			this.labelBorderWidth = 1;
			this.labelToolTip = "";
			this.labelUrl = "";
			this.labelMapAreaAttributes = "";
			this.labelPostbackValue = "";
			this.legendUrl = "";
			this.legendMapAreaAttributes = "";
			this.legendPostbackValue = "";
			if (name == null)
			{
				throw new ArgumentNullException("name", SR.ExceptionDataSeriesNameIsEmpty);
			}
			if (this.YValuesPerPoint < 1)
			{
				throw new ArgumentOutOfRangeException("yValues", SR.ExceptionDataSeriesYValuesPerPointIsZero);
			}
			this.InitProperties(name, yValues);
		}

		internal void ApplyPaletteColors()
		{
			var dataManager = base.Common.DataManager;
			var brightPastel = (this.Palette == ChartColorPalette.None) ? dataManager.Palette : this.Palette;
			if ((brightPastel == ChartColorPalette.None) && (dataManager.PaletteCustomColors.Length == 0))
				brightPastel = ChartColorPalette.BrightPastel;
			int index = 0;
			var colorArray = (brightPastel == ChartColorPalette.None) ? dataManager.PaletteCustomColors : ChartPaletteColors.GetPaletteColors(brightPastel);
			foreach (var point in this._points)
			{
				if ((!point.IsCustomPropertySet(CommonCustomProperties.Color) || point.tempColorIsSet) && !point.IsEmpty)
				{
					point.SetAttributeObject(CommonCustomProperties.Color, colorArray[index]);
					point.tempColorIsSet = true;
					index++;
					if (index >= colorArray.Length)
						index = 0;
				}
			}
		}

		internal void CheckSupportedTypes(Type type)
		{
			if (((((type != typeof(double)) && (type != typeof(DateTime))) && ((type != typeof(string)) && (type != typeof(int)))) && (((type != typeof(uint)) && (type != typeof(decimal))) && ((type != typeof(float)) && (type != typeof(short))))) && ((((type != typeof(ushort)) && (type != typeof(long))) && ((type != typeof(ulong)) && (type != typeof(byte)))) && (((type != typeof(sbyte)) && (type != typeof(DBNull))) && (type != typeof(bool)))))
				throw new ArgumentException(SR.ExceptionDataSeriesPointTypeUnsupported(type.ToString()));
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (this._fontCache != null)
				{
					this._fontCache.Dispose();
					this._fontCache = null;
				}
				if (this._emptyPointCustomProperties != null)
				{
					this._emptyPointCustomProperties.Dispose();
					this._emptyPointCustomProperties = null;
				}
				if (this._points != null)
				{
					this._points.Dispose();
					this._points = null;
				}
				if (this.fakeDataPoints != null)
				{
					this.fakeDataPoints.Dispose();
					this.fakeDataPoints = null;
				}
			}
			base.Dispose(disposing);
		}

		internal string GetCaption()
		{
			if (this.IsCustomPropertySet("SeriesCaption"))
				return base["SeriesCaption"];

			return this.Name;
		}

		internal static string GetChartTypeName(SeriesChartType type)
		{
			if (type == SeriesChartType.StackedArea100)
				return "100%StackedArea";

			if (type == SeriesChartType.StackedBar100)
				return "100%StackedBar";

			if (type == SeriesChartType.StackedColumn100)
				return "100%StackedColumn";

			return Enum.GetName(typeof(SeriesChartType), type);
		}

		internal IEnumerable GetDummyData(ChartValueType type)
		{
			var strArray = new string[] { "abc1", "abc2", "abc3", "abc4", "abc5", "abc6" };
			var timeArray = new DateTime[] { DateTime.Now.Date, DateTime.Now.Date.AddDays(1.0), DateTime.Now.Date.AddDays(2.0), DateTime.Now.Date.AddDays(3.0), DateTime.Now.Date.AddDays(4.0), DateTime.Now.Date.AddDays(4.0) };
			if (this._dummyDoubleValues == null)
			{
				var seed = 0;
				for (var i = 0; i < this.Name.Length; i++)
					seed += this.Name[i];
				var random = new Random(seed);
				this._dummyDoubleValues = new double[6];
				for (var j = 0; j < 6; j++)
					this._dummyDoubleValues[j] = random.Next(10, 100);
			}
			if (((type == ChartValueType.DateTime) || (type == ChartValueType.Date)) || (type == ChartValueType.DateTimeOffset))
				return timeArray;

			if (type == ChartValueType.Time)
				return new DateTime[] { DateTime.Now, DateTime.Now.AddMinutes(1.0), DateTime.Now.AddMinutes(2.0), DateTime.Now.AddMinutes(3.0), DateTime.Now.AddMinutes(4.0), DateTime.Now.AddMinutes(4.0) };

			if (type == ChartValueType.String)
				return strArray;

			return this._dummyDoubleValues;
		}

		internal void GetPointDepthAndGap(ChartGraphics graph, Axis axis, ref double pointDepth, ref double pointGapDepth)
		{
			string stringToParse = base["PixelPointDepth"];
			if (stringToParse != null)
			{
				try
				{
					pointDepth = CommonElements.ParseDouble(stringToParse);
				}
				catch
				{
					throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid2("PixelPointDepth"));
				}
				if (pointDepth <= 0.0)
					throw new InvalidOperationException(SR.ExceptionCustomAttributeIsNotLargerThenZiro("PixelPointDepth"));

				if (pointDepth > CustomPropertyRegistry.MaxValueOfPixelAttribute)
				{
					int num = 0;
					throw new InvalidOperationException(SR.ExceptionCustomAttributeMustBeInRange("PixelPointDepth", num.ToString(CultureInfo.CurrentCulture), CustomPropertyRegistry.MaxValueOfPixelAttribute.ToString(CultureInfo.CurrentCulture)));
				}
				var relativeSize = graph.GetRelativeSize(new SizeF((float)pointDepth, (float)pointDepth));
				pointDepth = relativeSize.Width;
				if ((axis.AxisPosition == AxisPosition.Left) || (axis.AxisPosition == AxisPosition.Right))
					pointDepth = relativeSize.Height;
			}
			stringToParse = base["PixelPointGapDepth"];
			if (stringToParse != null)
			{
				try
				{
					pointGapDepth = CommonElements.ParseDouble(stringToParse);
				}
				catch
				{
					throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid2("PixelPointGapDepth"));
				}
				if (pointGapDepth <= 0.0)
					throw new InvalidOperationException(SR.ExceptionCustomAttributeIsNotLargerThenZiro("PixelPointGapDepth"));

				if (pointGapDepth > CustomPropertyRegistry.MaxValueOfPixelAttribute)
				{
					int num2 = 0;
					throw new InvalidOperationException(SR.ExceptionCustomAttributeMustBeInRange("PixelPointGapDepth", num2.ToString(CultureInfo.CurrentCulture), CustomPropertyRegistry.MaxValueOfPixelAttribute.ToString(CultureInfo.CurrentCulture)));
				}
				var ef2 = graph.GetRelativeSize(new SizeF((float)pointGapDepth, (float)pointGapDepth));
				pointGapDepth = ef2.Width;
				if ((axis.AxisPosition == AxisPosition.Left) || (axis.AxisPosition == AxisPosition.Right))
					pointGapDepth = ef2.Height;
			}
		}

		internal double GetPointWidth(ChartGraphics graph, Axis axis, double interval, double defaultWidth)
		{
			var num = defaultWidth;
			var pixelInterval = 0.0;
			var stringToParse = base["PointWidth"];
			if (stringToParse != null)
				num = CommonElements.ParseDouble(stringToParse);
			pixelInterval = axis.GetPixelInterval(interval * num);
			var absoluteSize = graph.GetAbsoluteSize(new SizeF((float)pixelInterval, (float)pixelInterval));
			var width = (double)absoluteSize.Width;
			if ((axis.AxisPosition == AxisPosition.Left) || (axis.AxisPosition == AxisPosition.Right))
				width = absoluteSize.Height;
			var flag = false;
			var str2 = base["MinPixelPointWidth"];
			if (str2 != null)
			{
				var num4 = 0.0D;
				try
				{
					num4 = CommonElements.ParseDouble(str2);
				}
				catch
				{
					throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid2("MinPixelPointWidth"));
				}
				if (num4 <= 0.0D)
					throw new InvalidOperationException(SR.ExceptionCustomAttributeIsNotLargerThenZiro("MinPixelPointWidth"));

				if (num4 > CustomPropertyRegistry.MaxValueOfPixelAttribute)
				{
					var num6 = 0;
					throw new InvalidOperationException(SR.ExceptionCustomAttributeMustBeInRange("MinPixelPointWidth", num6.ToString(CultureInfo.CurrentCulture), CustomPropertyRegistry.MaxValueOfPixelAttribute.ToString(CultureInfo.CurrentCulture)));
				}
				if (width < num4)
				{
					flag = true;
					width = num4;
				}
			}
			str2 = base["MaxPixelPointWidth"];
			if (str2 != null)
			{
				var num5 = 0.0D;
				try
				{
					num5 = CommonElements.ParseDouble(str2);
				}
				catch
				{
					throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid2("MaxPixelPointWidth"));
				}
				if (num5 <= 0.0D)
					throw new InvalidOperationException(SR.ExceptionCustomAttributeIsNotLargerThenZiro("MaxPixelPointWidth"));

				if (width > num5)
				{
					flag = true;
					width = num5;
				}
			}
			str2 = base["PixelPointWidth"];
			if (str2 != null)
			{
				flag = true;
				width = 0.0;
				try
				{
					width = CommonElements.ParseDouble(str2);
				}
				catch
				{
					throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid2("PixelPointWidth"));
				}
				if (width <= 0.0D)
					throw new InvalidOperationException(SR.ExceptionCustomAttributeIsNotLargerThenZiro("PixelPointWidth"));

				if (width > CustomPropertyRegistry.MaxValueOfPixelAttribute)
				{
					var num7 = 0;
					throw new InvalidOperationException(SR.ExceptionCustomAttributeMustBeInRange("PixelPointWidth", num7.ToString(CultureInfo.CurrentCulture), CustomPropertyRegistry.MaxValueOfPixelAttribute.ToString(CultureInfo.CurrentCulture)));
				}
			}
			if (!flag)
				return pixelInterval;

			var relativeSize = graph.GetRelativeSize(new SizeF((float)width, (float)width));
			pixelInterval = relativeSize.Width;
			if ((axis.AxisPosition != AxisPosition.Left) && (axis.AxisPosition != AxisPosition.Right))
				return pixelInterval;

			return relativeSize.Height;
		}

		internal double GetTotalYValue()
		{
			return this.GetTotalYValue(0);
		}

		internal double GetTotalYValue(int yValueIndex)
		{
			if (yValueIndex == 0)
			{
				if (double.IsNaN(this._totalYvalue))
				{
					this._totalYvalue = 0.0;
					foreach (var point in this.Points)
						this._totalYvalue += point.YValues[yValueIndex];
				}
				return this._totalYvalue;
			}
			if (yValueIndex >= this.YValuesPerPoint)
				throw new InvalidOperationException(SR.ExceptionDataSeriesYValueIndexNotExists(yValueIndex.ToString(CultureInfo.InvariantCulture), this.Name));

			var num = 0.0D;
			foreach (var point2 in this.Points)
				num += point2.YValues[yValueIndex];
			return num;
		}

		private static DataPointCustomProperties InitializeDefaultCustomProperties()
		{
			DataPointCustomProperties properties = new DataPointCustomProperties(null, false);
			properties.SetDefault(true);
			properties.pointCustomProperties = true;
			return properties;
		}

		private void InitProperties(string name, int YValuesPerPoint)
		{
			this.font = this._fontCache.DefaultFont;
			base.series = this;
			this._emptyPointCustomProperties = new DataPointCustomProperties(this, false);
			this._emptyPointCustomProperties.series = this;
			this._points = new DataPointCollection(this);
			this.fakeDataPoints = new DataPointCollection(this);
			if (name != null)
			{
				base.Name = name;
			}
			if (YValuesPerPoint != 0)
			{
				this._yValuesPerPoint = YValuesPerPoint;
			}
			base.SetDefault(true);
			this._emptyPointCustomProperties.SetDefault(true);
			this._emptyPointCustomProperties.pointCustomProperties = true;
			this._smartLabelStyle = new SmartLabelStyle(this);
		}

		internal void Invalidate(bool invalidateAreaOnly, bool invalidateLegend)
		{
		}

		internal bool IsFastChartType()
		{
			return ((this.ChartType == SeriesChartType.FastLine) || (this.ChartType == SeriesChartType.FastPoint));
		}

		internal bool IsVisible()
		{
			return (this.Enabled && !string.IsNullOrEmpty(this.ChartArea));
		}

		internal bool IsXValueDateTime()
		{
			if (((this.XValueType != ChartValueType.Date) && (this.XValueType != ChartValueType.DateTime)) && ((this.XValueType != ChartValueType.Time) && (this.XValueType != ChartValueType.DateTimeOffset)))
			{
				return false;
			}
			return true;
		}

		internal bool IsYValueDateTime()
		{
			if (((this.YValueType != ChartValueType.Date) && (this.YValueType != ChartValueType.DateTime)) && ((this.YValueType != ChartValueType.Time) && (this.YValueType != ChartValueType.DateTimeOffset)))
			{
				return false;
			}
			return true;
		}

		internal static void MovePositionMarkers(Series fromSeries, Series toSeries)
		{
			foreach (DataPoint point in fromSeries.Points)
			{
				if (point.IsCustomPropertySet("OriginalPointIndex"))
				{
					int result = -1;
					if ((int.TryParse(point["OriginalPointIndex"], NumberStyles.Integer, CultureInfo.InvariantCulture, out result) && (result > -1)) && (result < toSeries.Points.Count))
					{
						toSeries.Points[result].positionRel = point.positionRel;
					}
				}
			}
		}

		internal void PrepareData(ISite controlSite, bool applyPaletteColors)
		{
			if (this.IsVisible())
			{
				base.Chart.ChartAreas.VerifyNameReference(this.ChartArea);
				if ((this.Points.Count > 0) && (this.Points[0].YValues.Length < this.YValuesPerPoint))
				{
					foreach (DataPoint point in this.Points)
					{
						point.ResizeYValueArray(this.YValuesPerPoint);
					}
				}
				bool flag = false;
				if (this.Points.Count == 0)
				{
					if ((controlSite != null) && controlSite.DesignMode)
					{
						flag = true;
					}
					else if (this.IsCustomPropertySet("UseDummyData") && (string.Compare(base["UseDummyData"], "True", StringComparison.OrdinalIgnoreCase) == 0))
					{
						flag = true;
					}
				}
				if (flag)
				{
					if (this.IsXValueDateTime() || (this._xValueType == ChartValueType.String))
					{
						this.Points.DataBindXY(this.GetDummyData(this._xValueType), new IEnumerable[] { this.GetDummyData(this._yValueType) });
					}
					else
					{
						double[] xValue = new double[] { 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 };
						if (this.ChartType == SeriesChartType.Polar)
						{
							xValue = new double[] { 0.0, 45.0, 115.0, 145.0, 180.0, 220.0 };
						}
						this.Points.DataBindXY(xValue, new IEnumerable[] { this.GetDummyData(this._yValueType) });
					}
					if (this.YValuesPerPoint > 1)
					{
						foreach (DataPoint point2 in this.Points)
						{
							for (int i = 1; i < this.YValuesPerPoint; i++)
							{
								point2.YValues[i] = point2.YValues[0];
							}
							if (this.YValuesPerPoint >= 2)
							{
								point2.YValues[1] = (point2.YValues[0] / 2.0) - 1.0;
							}
							if (this.YValuesPerPoint >= 4)
							{
								point2.YValues[2] = point2.YValues[1] + ((point2.YValues[0] - point2.YValues[1]) / 3.0);
								point2.YValues[3] = point2.YValues[2] + ((point2.YValues[0] - point2.YValues[1]) / 3.0);
							}
							if (this.YValuesPerPoint >= 6)
							{
								point2.YValues[4] = point2.YValues[2] + ((point2.YValues[3] - point2.YValues[2]) / 2.0);
								point2.YValues[5] = point2.YValues[2] + ((point2.YValues[3] - point2.YValues[2]) / 3.0);
							}
						}
					}
					base["TempDesignData"] = "true";
				}
				if (this._xValueType == ChartValueType.Auto)
				{
					this._xValueType = ChartValueType.Double;
					this.autoXValueType = true;
				}
				if (this._yValueType == ChartValueType.Auto)
				{
					this._yValueType = ChartValueType.Double;
					this.autoYValueType = true;
				}
				this.indexedXValueType = this._xValueType;
				this._totalYvalue = double.NaN;
				if ((base.Chart != null) && base.Chart.ChartPicture.SuppressExceptions)
				{
					Axis axis = base.Chart.ChartAreas[this.ChartArea].GetAxis(AxisName.Y, this.YAxisType, this.YSubAxisName);
					foreach (DataPoint point3 in this.Points)
					{
						for (int j = 0; j < point3.YValues.Length; j++)
						{
							if (axis.IsLogarithmic && (point3.YValues[j] <= 0.0))
							{
								point3.YValues[j] = 1.0;
								point3.IsEmpty = true;
							}
							if (double.IsNaN(point3.YValues[j]))
							{
								point3.YValues[j] = 0.0;
								point3.IsEmpty = true;
							}
						}
					}
				}
				ErrorBarChart.GetDataFromLinkedSeries(this);
				ErrorBarChart.CalculateErrorAmount(this);
				BoxPlotChart.CalculateBoxPlotFromLinkedSeries(this);
				RenkoChart.PrepareData(this);
				ThreeLineBreakChart.PrepareData(this);
				KagiChart.PrepareData(this);
				PointAndFigureChart.PrepareData(this);
				PieChart.PrepareData(this);
				if (applyPaletteColors)
				{
					this.ApplyPaletteColors();
				}
			}
		}

		internal override string ReplaceKeywords(string strOriginal)
		{
			if ((strOriginal == null) || (strOriginal.Length == 0))
			{
				return strOriginal;
			}
			string str = DataPoint.ReplaceCustomPropertyKeyword(strOriginal.Replace(@"\n", "\n").Replace("#SERIESNAME", this.Name).Replace("#SER", this.Name), this);
			str = this.ReplaceOneKeyword(base.Chart, this, base.Tag, ChartElementType.Nothing, str, "#TOTAL", SeriesValuesFormulaType.Total, this.YValueType, "");
			str = this.ReplaceOneKeyword(base.Chart, this, base.Tag, ChartElementType.Nothing, str, "#AVG", SeriesValuesFormulaType.Average, this.YValueType, "");
			str = this.ReplaceOneKeyword(base.Chart, this, base.Tag, ChartElementType.Nothing, str, "#MAX", SeriesValuesFormulaType.Maximum, this.YValueType, "");
			str = this.ReplaceOneKeyword(base.Chart, this, base.Tag, ChartElementType.Nothing, str, "#MIN", SeriesValuesFormulaType.Minimum, this.YValueType, "");
			str = this.ReplaceOneKeyword(base.Chart, this, base.Tag, ChartElementType.Nothing, str, "#FIRST", SeriesValuesFormulaType.First, this.YValueType, "");
			return this.ReplaceOneKeyword(base.Chart, this, base.Tag, ChartElementType.Nothing, str, "#LAST", SeriesValuesFormulaType.Last, this.YValueType, "").Replace("#LEGENDTEXT", base.LegendText);
		}

		internal string ReplaceOneKeyword(Chart chart, object obj, object objTag, ChartElementType elementType, string strOriginal, string keyword, double value, ChartValueType valueType, string defaultFormat)
		{
			string format = strOriginal;
			int startIndex = -1;
			while ((startIndex = format.IndexOf(keyword, StringComparison.Ordinal)) != -1)
			{
				int num2 = startIndex + keyword.Length;
				string str2 = defaultFormat;
				if ((format.Length > num2) && (format[num2] == '{'))
				{
					int index = format.IndexOf('}', num2);
					if (index == -1)
					{
						throw new InvalidOperationException(SR.ExceptionDataSeriesKeywordFormatInvalid(format));
					}
					str2 = format.Substring(num2, index - num2).Trim(new char[] { '{', '}' });
					num2 = index + 1;
				}
				format = format.Remove(startIndex, num2 - startIndex).Insert(startIndex, ValueConverter.FormatValue(chart, obj, objTag, value, str2, valueType, elementType));
			}
			return format;
		}

		internal string ReplaceOneKeyword(Chart chart, object obj, object objTag, ChartElementType elementType, string strOriginal, string keyword, SeriesValuesFormulaType formulaType, ChartValueType valueType, string defaultFormat)
		{
			string format = strOriginal;
			int startIndex = -1;
			while ((startIndex = format.IndexOf(keyword, StringComparison.Ordinal)) != -1)
			{
				int num2 = startIndex + keyword.Length;
				int yValueIndex = 0;
				if (((format.Length > (num2 + 1)) && (format[num2] == 'Y')) && char.IsDigit(format[num2 + 1]))
				{
					yValueIndex = int.Parse(format.Substring(num2 + 1, 1), CultureInfo.InvariantCulture);
					num2 += 2;
				}
				string str2 = defaultFormat;
				if ((format.Length > num2) && (format[num2] == '{'))
				{
					int index = format.IndexOf('}', num2);
					if (index == -1)
					{
						throw new InvalidOperationException(SR.ExceptionDataSeriesKeywordFormatInvalid(format));
					}
					str2 = format.Substring(num2, index - num2).Trim(new char[] { '{', '}' });
					num2 = index + 1;
				}
				format = format.Remove(startIndex, num2 - startIndex);
				double totalYValue = this.GetTotalYValue(yValueIndex);
				double minValue = 0.0;
				switch (formulaType)
				{
					case SeriesValuesFormulaType.Total:
						minValue = totalYValue;
						break;

					case SeriesValuesFormulaType.Average:
						if (this.Points.Count > 0)
						{
							minValue = totalYValue / ((double)this.Points.Count);
						}
						break;

					case SeriesValuesFormulaType.Maximum:
						if (this.Points.Count > 0)
						{
							minValue = double.MinValue;
							foreach (DataPoint point in this.Points)
							{
								minValue = Math.Max(minValue, point.YValues[yValueIndex]);
							}
						}
						break;

					case SeriesValuesFormulaType.Minimum:
						if (this.Points.Count > 0)
						{
							minValue = double.MaxValue;
							foreach (DataPoint point2 in this.Points)
							{
								minValue = Math.Min(minValue, point2.YValues[yValueIndex]);
							}
						}
						break;

					case SeriesValuesFormulaType.First:
						if (this.Points.Count > 0)
						{
							minValue = this.Points[0].YValues[yValueIndex];
						}
						break;

					case SeriesValuesFormulaType.Last:
						if (this.Points.Count > 0)
						{
							minValue = this.Points[this.Points.Count - 1].YValues[yValueIndex];
						}
						break;
				}
				format = format.Insert(startIndex, ValueConverter.FormatValue(chart, obj, objTag, minValue, str2, valueType, elementType));
			}
			return format;
		}

		internal void ResetAutoValues()
		{
			this.ResetAutoValues(true);
		}

		internal void ResetAutoValues(bool reset)
		{
			if (this.IsCustomPropertySet("TempDesignData"))
			{
				this.DeleteCustomProperty("TempDesignData");
				bool flag = true;
				if ((base.Chart != null) && !base.Chart.IsDesignMode())
				{
					flag = false;
				}
				if (flag)
				{
					this.fakeDataPoints.Clear();
					foreach (DataPoint point in this.Points)
					{
						this.fakeDataPoints.Add(point);
					}
				}
				this.Points.Clear();
			}
			if (base.tempColorIsSet)
			{
				base.tempColorIsSet = false;
				base.Color = Color.Empty;
			}
			if (this.tempMarkerStyleIsSet)
			{
				this.tempMarkerStyleIsSet = false;
				base.MarkerStyle = MarkerStyle.None;
			}
			foreach (DataPoint point2 in this._points)
			{
				if (point2.tempColorIsSet)
				{
					point2.Color = Color.Empty;
				}
			}
			if (reset && ((base.Chart == null) || !base.Chart.Serializing))
			{
				if (this.autoXValueType)
				{
					this._xValueType = ChartValueType.Auto;
					this.autoXValueType = false;
				}
				if (this.autoYValueType)
				{
					this._yValueType = ChartValueType.Auto;
					this.autoYValueType = false;
				}
			}
		}

		public void Sort(IComparer<DataPoint> comparer)
		{
			if (comparer == null)
			{
				throw new ArgumentNullException("comparer");
			}
			this.Points.ItemList.Sort(comparer);
			this.Invalidate(true, false);
		}

		public void Sort(PointSortOrder pointSortOrder)
		{
			this.Sort(pointSortOrder, "Y");
		}

		public void Sort(PointSortOrder pointSortOrder, string sortBy)
		{
			if (sortBy == null)
			{
				throw new ArgumentNullException("sortBy");
			}
			DataPointComparer comparer = new DataPointComparer(this, pointSortOrder, sortBy);
			this.Points.ItemList.Sort(comparer);
			this.Invalidate(true, false);
		}

		internal bool UnPrepareData(ISite controlSite)
		{
			bool flag = false;
			if (RenkoChart.UnPrepareData(this))
			{
				flag = true;
			}
			if (ThreeLineBreakChart.UnPrepareData(this))
			{
				flag = true;
			}
			if (KagiChart.UnPrepareData(this))
			{
				flag = true;
			}
			if (PointAndFigureChart.UnPrepareData(this))
			{
				flag = true;
			}
			if (PieChart.UnPrepareData(this))
			{
				flag = true;
			}
			if (this._isXValueIndexed)
			{
				this._xValueType = this.indexedXValueType;
			}
			bool reset = true;
			this.ResetAutoValues(reset);
			return flag;
		}

		[Browsable(false)]
		[PersistenceMode(PersistenceMode.Attribute)]
		[SRCategory("CategoryAttributeMisc")]
		[Bindable(true)]
		[DefaultValue("")]
		[SRDescription("DescriptionAttributeAxisLabel")]
		public override string AxisLabel
		{
			get
			{
				return base.AxisLabel;
			}
			set
			{
				base.AxisLabel = value;
				this.Invalidate(true, false);
			}
		}

		[SRCategory("CategoryAttributeChart")]
		[TypeConverter(typeof(SeriesAreaNameConverter))]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_ChartArea")]
		[DefaultValue("")]
		public string ChartArea
		{
			get
			{
				return this._chartArea;
			}
			set
			{
				if (value != this._chartArea)
				{
					if ((base.Chart != null) && (base.Chart.ChartAreas != null))
					{
						base.Chart.ChartAreas.VerifyNameReference(value);
					}
					this._chartArea = value;
					this.Invalidate(false, true);
				}
			}
		}

		[SRCategory("CategoryAttributeChart")]
		[SRDescription("DescriptionAttributeSeries_Type")]
		[DefaultValue(10)]
		[RefreshProperties(RefreshProperties.All)]
		[Editor(typeof(ChartTypeEditor), typeof(UITypeEditor))]
		[Bindable(true)]
		public SeriesChartType ChartType
		{
			get
			{
				SeriesChartType column = SeriesChartType.Column;
				if (string.Compare(this.ChartTypeName, "100%StackedArea", StringComparison.OrdinalIgnoreCase) == 0)
				{
					return SeriesChartType.StackedArea100;
				}
				if (string.Compare(this.ChartTypeName, "100%StackedBar", StringComparison.OrdinalIgnoreCase) == 0)
				{
					return SeriesChartType.StackedBar100;
				}
				if (string.Compare(this.ChartTypeName, "100%StackedColumn", StringComparison.OrdinalIgnoreCase) == 0)
				{
					return SeriesChartType.StackedColumn100;
				}
				try
				{
					column = (SeriesChartType)Enum.Parse(typeof(SeriesChartType), this.ChartTypeName, true);
				}
				catch (ArgumentException)
				{
				}
				return column;
			}
			set
			{
				this.ChartTypeName = GetChartTypeName(value);
			}
		}

		[TypeConverter(typeof(ChartTypeConverter))]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[SRCategory("CategoryAttributeChart")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_Type")]
		[DefaultValue("Column")]
		[Browsable(false)]
		[Editor(typeof(ChartTypeEditor), typeof(UITypeEditor))]
		[RefreshProperties(RefreshProperties.All)]
		[EditorBrowsable(EditorBrowsableState.Never)]
		[SerializationVisibility(SerializationVisibility.Hidden)]
		public string ChartTypeName
		{
			get
			{
				return this._chartType;
			}
			set
			{
				if (((this._chartType != value) && (value.Length > 0)) && (base.Common != null))
				{
					ChartTypeRegistry chartTypeRegistry = base.Common.ChartTypeRegistry;
					if (chartTypeRegistry != null)
					{
						IChartType chartType = chartTypeRegistry.GetChartType(value);
						if (this._yValuesPerPoint < chartType.YValuesPerPoint)
						{
							this._yValuesPerPoint = chartType.YValuesPerPoint;
							if (this._points.Count > 0)
							{
								foreach (DataPoint point in this._points)
								{
									point.ResizeYValueArray(this._yValuesPerPoint);
								}
							}
						}
					}
				}
				this._chartType = value;
				this.Invalidate(false, true);
			}
		}

		[SRCategory("CategoryAttributeEmptyPoints")]
		[SRDescription("DescriptionAttributeSeries_EmptyPointStyle")]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[Bindable(true)]
		public DataPointCustomProperties EmptyPointStyle
		{
			get
			{
				return this._emptyPointCustomProperties;
			}
			set
			{
				if ((value.series == null) && (this._emptyPointCustomProperties.series != null))
				{
					value.series = this._emptyPointCustomProperties.series;
				}
				this._emptyPointCustomProperties = value;
				this._emptyPointCustomProperties.pointCustomProperties = false;
				this._emptyPointCustomProperties.SetDefault(false);
				this._emptyPointCustomProperties.pointCustomProperties = true;
				this._emptyPointCustomProperties.Parent = this;
				this.Invalidate(true, false);
			}
		}

		[SRDescription("DescriptionAttributeSeries_Enabled")]
		[Bindable(true)]
		[SRCategory("CategoryAttributeAppearance")]
		[NotifyParentProperty(true)]
		[ParenthesizePropertyName(true)]
		[PersistenceMode(PersistenceMode.Attribute)]
		[DefaultValue(true)]
		public bool Enabled
		{
			get
			{
				return this._enabled;
			}
			set
			{
				this._enabled = value;
				this.Invalidate(true, true);
			}
		}

		internal FontCache FontCache
		{
			get
			{
				return this._fontCache;
			}
		}

		[Bindable(true)]
		[PersistenceMode(PersistenceMode.Attribute)]
		[SRCategory("CategoryAttributeData")]
		[SRDescription("DescriptionAttributeSeries_XValueIndexed")]
		[DefaultValue(false)]
		public bool IsXValueIndexed
		{
			get
			{
				return this._isXValueIndexed;
			}
			set
			{
				this._isXValueIndexed = value;
				this.Invalidate(true, false);
			}
		}

		[Bindable(true), SRCategory("CategoryAttributeLegend")]
		[TypeConverter(typeof(SeriesLegendNameConverter))]
		[SRDescription("DescriptionAttributeSeries_Legend")]
		[DefaultValue("")]
		public string Legend
		{
			get
			{
				return this._legend;
			}
			set
			{
				if (value != this._legend)
				{
					if ((base.Chart != null) && (base.Chart.Legends != null))
					{
						base.Chart.Legends.VerifyNameReference(value);
					}
					this._legend = value;
					this.Invalidate(false, true);
				}
			}
		}

		[SRCategory("CategoryAttributeMarker")]
		[Bindable(true)]
		[DefaultValue(1)]
		[SRDescription("DescriptionAttributeSeries_MarkerStep")]
		public int MarkerStep
		{
			get
			{
				return this._markersStep;
			}
			set
			{
				if (value <= 0)
				{
					throw new ArgumentException(SR.ExceptionMarkerStepNegativeValue, "value");
				}
				this._markersStep = value;
				this.Invalidate(true, false);
			}
		}

		[PersistenceMode(PersistenceMode.Attribute)]
		[SRCategory("CategoryAttributeData")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_Name")]
		public override string Name
		{
			get
			{
				return base.Name;
			}
			set
			{
				base.Name = value;
			}
		}

		[DefaultValue(0)]
		[Editor(typeof(ColorPaletteEditor), typeof(UITypeEditor))]
		[SRCategory("CategoryAttributeAppearance")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributePalette")]
		public ChartColorPalette Palette
		{
			get
			{
				return this._colorPalette;
			}
			set
			{
				this._colorPalette = value;
				this.Invalidate(true, true);
			}
		}

		[Bindable(true)]
		[Editor(typeof(DataPointCollectionEditor), typeof(UITypeEditor))]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[SRCategory("CategoryAttributeData")]
		[SRDescription("DescriptionAttributeSeries_Points")]
		public DataPointCollection Points
		{
			get
			{
				return this._points;
			}
		}

		[SRCategory("CategoryAttributeAppearance")]
		[SRDescription("DescriptionAttributeShadowColor")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[Bindable(true)]
		[DefaultValue(typeof(Color), "128,0,0,0")]
		public Color ShadowColor
		{
			get
			{
				return this._shadowColor;
			}
			set
			{
				this._shadowColor = value;
				this.Invalidate(true, true);
			}
		}

		[DefaultValue(0)]
		[SRDescription("DescriptionAttributeShadowOffset")]
		[Bindable(true)]
		[SRCategory("CategoryAttributeAppearance")]
		public int ShadowOffset
		{
			get
			{
				return this._shadowOffset;
			}
			set
			{
				this._shadowOffset = value;
				this.Invalidate(true, true);
			}
		}

		[SRCategory("CategoryAttributeLabel")]
		[SRDescription("DescriptionAttributeSeries_SmartLabels")]
		[Bindable(true)]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[Browsable(true)]
		public SmartLabelStyle SmartLabelStyle
		{
			get
			{
				return this._smartLabelStyle;
			}
			set
			{
				value.chartElement = this;
				this._smartLabelStyle = value;
				this.Invalidate(false, false);
			}
		}

		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_XAxisType")]
		[DefaultValue(0)]
		[SRCategory("CategoryAttributeAxes")]
		public AxisType XAxisType
		{
			get
			{
				return this._xAxisType;
			}
			set
			{
				this._xAxisType = value;
				this.Invalidate(true, false);
			}
		}

		[DefaultValue("")]
		[SRCategory("CategoryAttributeAxes")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_XSubAxisName")]
		internal string XSubAxisName
		{
			get
			{
				return string.Empty;
			}
			set
			{
			}
		}

		[SRCategory("CategoryAttributeDataSource")]
		[TypeConverter(typeof(SeriesDataFieldXConvertor))]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_ValueMemberX")]
		[DefaultValue("")]
		public string XValueMember
		{
			get
			{
				return this._dataSourceXMember;
			}
			set
			{
				if (value == "(none)")
				{
					this._dataSourceXMember = string.Empty;
				}
				else
				{
					this._dataSourceXMember = value;
				}
				if ((base.Common != null) && (base.Common.ChartPicture != null))
				{
					base.Common.ChartPicture.boundToDataSource = false;
				}
			}
		}

		[SRCategory("CategoryAttributeData")]
		[PersistenceMode(PersistenceMode.Attribute)]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_XValueType")]
		[DefaultValue(0)]
		public ChartValueType XValueType
		{
			get
			{
				return this._xValueType;
			}
			set
			{
				this._xValueType = value;
				this.autoXValueType = false;
				this.Invalidate(true, false);
			}
		}

		[SRCategory("CategoryAttributeAxes")]
		[SRDescription("DescriptionAttributeSeries_YAxisType")]
		[DefaultValue(0)]
		[Bindable(true)]
		public AxisType YAxisType
		{
			get
			{
				return this._yAxisType;
			}
			set
			{
				this._yAxisType = value;
				this.Invalidate(true, false);
			}
		}

		[SRCategory("CategoryAttributeAxes")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_YSubAxisName")]
		[DefaultValue("")]
		internal string YSubAxisName
		{
			get
			{
				return string.Empty;
			}
			set
			{
			}
		}

		[TypeConverter(typeof(SeriesDataFieldYConvertor))]
		[SRCategory("CategoryAttributeDataSource")]
		[Bindable(true)]
		[SRDescription("DescriptionAttributeSeries_ValueMembersY")]
		[DefaultValue("")]
		[Editor(typeof(SeriesDataFieldValueAxisUITypeEditor), typeof(UITypeEditor))]
		public string YValueMembers
		{
			get
			{
				return this._dataSourceYMembers;
			}
			set
			{
				if (value == "(none)")
				{
					this._dataSourceYMembers = string.Empty;
				}
				else
				{
					this._dataSourceYMembers = value;
				}
				if ((base.Common != null) && (base.Common.ChartPicture != null))
				{
					base.Common.ChartPicture.boundToDataSource = false;
				}
			}
		}

		[Bindable(true), PersistenceMode(PersistenceMode.Attribute), SRCategory("CategoryAttributeData"), SRDescription("DescriptionAttributeSeries_YValuesPerPoint"), DefaultValue(1)]
		public int YValuesPerPoint
		{
			get
			{
				if ((this._checkPointsNumber && (this.ChartTypeName.Length > 0)) && (base.Common != null))
				{
					this._checkPointsNumber = false;
					IChartType chartType = base.Common.ChartTypeRegistry.GetChartType(this.ChartTypeName);
					if (chartType.YValuesPerPoint > this._yValuesPerPoint)
					{
						this._yValuesPerPoint = chartType.YValuesPerPoint;
						if (this._points.Count > 0)
						{
							foreach (DataPoint point in this._points)
							{
								point.ResizeYValueArray(this._yValuesPerPoint);
							}
						}
					}
				}
				return this._yValuesPerPoint;
			}
			set
			{
				if ((value < 1) || (value > 0x20))
				{
					throw new ArgumentOutOfRangeException("value", SR.ExceptionDataSeriesYValueNumberInvalid);
				}
				this._checkPointsNumber = true;
				if (this._points.Count > 0)
				{
					foreach (DataPoint point in this._points)
					{
						point.ResizeYValueArray(value);
					}
				}
				this._yValuesPerPoint = value;
				this.Invalidate(true, false);
			}
		}

		[SRCategory("CategoryAttributeData"), TypeConverter(typeof(SeriesYValueTypeConverter)), Bindable(true), SRDescription("DescriptionAttributeSeries_YValueType"), DefaultValue(0), PersistenceMode(PersistenceMode.Attribute)]
		public ChartValueType YValueType
		{
			get
			{
				return this._yValueType;
			}
			set
			{
				this._yValueType = value;
				this.autoYValueType = false;
				this.Invalidate(true, false);
			}
		}

		internal enum SeriesValuesFormulaType
		{
			Total,
			Average,
			Maximum,
			Minimum,
			First,
			Last
		}
	}
}

